using System;
using System.Collections.Generic;
using System.Text;
using Entites;
using DAL;
using Utility;

namespace BUS
{
   public class SanPhamBUS
    {
         public static void Insert(SanPham pham)
        {
            SanPhamDAL phamDAL = new SanPhamDAL();
            phamDAL.Insert(pham);
        }
        public static void Update(SanPham pham)
        {
            SanPhamDAL phamDAL = new SanPhamDAL();
            phamDAL.Update(pham);
        }
        public static void Delete(int iD)
        {
            SanPhamDAL phamDAL = new SanPhamDAL();
            phamDAL.Delete(iD);
        }
        public static tbSanPhamCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            SanPhamDAL phamDAL = new SanPhamDAL();
            return phamDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbSanPhamCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            SanPhamDAL phamDAL = new SanPhamDAL();
            return phamDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
        }
       public static SanPham GetByID(int iD)
       {
           int total = 0;
           Criteria cri = new Criteria();
           cri.add(Condition.AND, tbSanPhamColumns.MaSP.ToString(), Condition.EQUAL, iD);
           SanPhamDAL phamDAL = new SanPhamDAL();
           tbSanPhamCollection sanphamcollection = phamDAL.Get(cri.Criter,
                 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
           if (sanphamcollection.Count > 0)
               return sanphamcollection[0];
           return null;
       }
      
        public static tbSanPhamCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            SanPhamDAL phamDAL = new SanPhamDAL();
            return phamDAL.Get(cri.Criter, 1, number,
             tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbSanPhamCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            SanPhamDAL phamDAL = new SanPhamDAL();
            return phamDAL.Get(cri.Criter, 1, number,
               tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
    }

